<?
    class App_Integral_logModel extends AppModel {
        protected $tableName='integral_log';
        protected $_map=array(//字符映射
//            'operater'=>'mname',
//            'ruleName'=>'rulename',
//            'content'=>'iremark',
//            'marks'=>'changenum'
        );
        //获取个人积分总数
        public function total($map){
            $check=D('integral_log')->where($map)->field('sum(changenum) as total')->select();//总数
            $arr['total']=$check['total'];
            $map['changenum']=array('gt','0');
            $add=D('integral_log')->where($map)->field('sum(changenum) as award')->select();//加分项
            $arr['award']=$add['award'];
            $map['changenum']=array('lt','0');
            $cut=D('integral_log')->where($map)->field('sum(changenum) as deduction')->select();//减分项
            $arr['deduction']=$cut['deduction'];
            $data = $check?$this->parseFieldsMap($arr):'';
            return $data;
        }
        //获取个人积分明细
        public function detail($map){
            $check=D('integral_log')->alias('i')->join('__MEMBER__ m on m.id=i.rewarder_id')->join('__INTEGRAL_RULE__ r on i.rule_id=r.id')->where($map)->field('i.type_id,i.changenum as marks,r.name as ruleName,i.remark as content,m.name as operater,i.time as time')->select();//,i.remark
            $data=$check?$this->parseFieldsMap($check):'';
            return $data;
        }
    }